package com.objectdraw.client;
import java.net.*;
import java.io.*;

//Carl

public class clientcomm {
	private Socket mySocket;
    private PrintWriter out = null;
    private BufferedReader in = null;
	public clientcomm(String host) throws UnknownHostException, IOException{
		mySocket = new Socket(host, 5454);
		out = new PrintWriter(mySocket.getOutputStream(), true);
		in = new BufferedReader(new InputStreamReader(mySocket.getInputStream()));
	}

	public void sendMessage(String msg){
		out.println(msg);
	}
	public boolean ready(){
		try {
			return in.ready();
		} catch (IOException e) {
			return false;
		}
	}
	public String readMessage() throws IOException{
		return in.readLine();
	}

	public void close() {
		try {
			sendMessage("disconnect ");
			if(mySocket.isClosed()){
				mySocket.close();
			}
		} catch (IOException e) {
			e.printStackTrace();
		}
		
	}
}
